package com.imon.jmxbox;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.task.SyncTaskExecutor;

public class App {

	private static final Log LOG = LogFactory.getLog(App.class);

	@Resource(type = SpringFrontDeskImpl.class)
	private FrontDesk frontDesk;

	@Resource(type = SpringBackOfficeImpl.class)
	private BackOffice backOffice;

	@Resource
	private SyncTaskExecutor syncTaskExecutor;

	public static void main(String[] args) {
		LOG.info("Hello World!");

		ApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext.xml");

		App app = context.getBean(App.class);
		app.run();
	}

	private void run() {
		syncTaskExecutor.execute(new Runnable() {

			public void run() {
				frontDesk.sendMail(new Mail("1234", "US", 1.15));
			}
		});

		syncTaskExecutor.execute(new Runnable() {
			public void run() {
				Mail receiveMail = backOffice.receiveMail();
				LOG.info(String.format("Received message: %s", receiveMail));
			}
		});
	}
}